import StorageUtils from "../btoolkit/StorageUtils";
import QuLe, { EventOnRemoteConfigLoaded } from "../btoolkit/sdk/QuLe";
import EventManager from "../btoolkit/EventManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class AddFavorites extends cc.Component {

    static get hasClickFavoritesTip() {
        return StorageUtils.readBool('HasClickFavoritesTip');
    }
    static set hasClickFavoritesTip(b: boolean) {
        StorageUtils.saveBool('HasClickFavoritesTip', b);
    }

    onLoad() {
        this.node.active = false;

        this.node.on(cc.Node.EventType.TOUCH_END, () => {
            AddFavorites.hasClickFavoritesTip = true;
            this.node.destroy();
        });


        if (AddFavorites.hasClickFavoritesTip) {
            this.node.destroy();
        }
        
        if(QuLe.instance.remoteConfig){
            this.setVisibleByConfig();
        }else{
            EventManager.addEvent(EventOnRemoteConfigLoaded, ()=>{
                this.setVisibleByConfig();
            });
        }
    }

    setVisibleByConfig(){
        if(QuLe.instance.remoteConfig.addFavorites){
            this.node.active = true;
        }else{
            this.node.destroy();
        }
    }

}
